<template>
  <div class="tab-control">
    <div
      class="tab-control-item"
      :class="{ active:index === currentIndex }"
      @click="itemActive(index)"
      v-for="(item,index) of titles"
      :key="item"
    >
      <span>{{ item }}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: "TabControl",
  props: {
    titles: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  data() {
    return {
      currentIndex: 0
    };
  },
  methods: {
    itemActive(index) {
      this.currentIndex = index;
      this.$emit("itemClick", index);
    }
  }
};
</script>

<style lang="less" scoped>
.tab-control {
  display: flex;
  text-align: center;
  background-color: #fff;
  .tab-control-item {
    flex: 1;
    line-height: 40px;
    height: 40px;
    &.active {
      color: var(--color-high-text);
      span {
        border-bottom: 2px solid var(--color-high-text);
      }
    }
    span {
      padding: 3px;
      font-size: 14px;
    }
  }
}
</style>